package com.example.demo.service;

import com.example.demo.entity.Element;
import com.example.demo.repository.ElementRepository;
import com.study.mongodbdynamicdatasource.anno.MongoDS;
import com.study.mongodbdynamicdatasource.util.AuthUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @Name: ElementService
 * @Description: java类作用描述
 * @Author: yn
 * @CreateDate: 2023/6/15 10:38
 * @Remark: 特殊说明
 * @Version: 1.0
 */
@Service
public class ElementService {

	@Autowired
	ElementRepository elementRepository;

	public Element saveElement(Element element) throws ExecutionException, InterruptedException {
		saveElementAuto(element);
		element.setId(null);
		element.setTenantId(AuthUtil.getTenantId());
		return saveElementAuto(element);
	}

	@MongoDS("000")
	public Element saveElementAuto(Element element){
		return elementRepository.insert(element);
	}

	public List<Element> findAll() {
		return elementRepository.findAll();
	}
}
